<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('盘点列表')" />
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse" style="display: none">
            <form id="formId">
                <input name="assetId" type="text" th:value="${assetId}"/>
                <input name="inventoryId" type="text" th:value="${inventoryId}"/>
            </form>
        </div>
        <div class="btn-group-sm" id="toolbar" role="group">
            <a class="btn btn-danger multiple disabled" onclick="lostAll()">
                <i class="fa fa-remove"></i> 批量遗失
            </a>
            <a class="btn btn-danger multiple disabled" onclick="scrapAll()">
                <i class="fa fa-remove"></i> 批量报废
            </a>
        </div>
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer" />
<script th:inline="javascript">
    var sUserAgent = navigator.userAgent.toLowerCase();
    var bIsIpad = sUserAgent.match(/ipad/i) == 'ipad';
    var bIsIphone = sUserAgent.match(/iphone os/i) == 'iphone os';
    var bIsMidp = sUserAgent.match(/midp/i) == 'midp';
    var bIsUc7 = sUserAgent.match(/rv:1.2.3.4/i) == 'rv:1.2.3.4';
    var bIsUc = sUserAgent.match(/ucweb/i) == 'web';
    var bIsCE = sUserAgent.match(/windows ce/i) == 'windows ce';
    var bIsWM = sUserAgent.match(/windows mobile/i) == 'windows mobile';
    var bIsAndroid = sUserAgent.match(/android/i) == 'android';
    var isNotPc;
    if(bIsIpad || bIsIphone || bIsMidp || bIsUc7 || bIsUc || bIsCE || bIsWM || bIsAndroid ){
        isNotPc = true
        $("#toolbar").hide();
    }else{
        isNotPc = false
    }
    var prefix = ctx + "inventory/inventory";

    $(function() {
        var options = {
            url: prefix + "/noInventoryList",
            exportUrl: prefix + "/exportDetail",
            modalName: "盘点",
            sortName:"updateTime",
            sortOrder:"desc",
            height:560,
            pagination: false,
            columns: [{
                checkbox: true
                },
                {
                    field : 'inventoryNo',
                    title : '资产序号'
                },
                {
                    field : 'inventoryId',
                    title : '盘点编号'
                },
                {
                    field : 'assetNo',
                    title : '卡片编号'
                },
                {
                    field : 'assetCode',
                    title : '资产编号',
                },
                {
                    field : 'assetName',
                    title : '资产名称'
                },
                {
                    field : 'specifications',
                    title : '规格'
                },
                {
                    field : 'assetModel',
                    title : '型号'
                },{
                    title: '操作',
                    align: 'left',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-danger btn-xs " href="javascript:void(0)" onclick="lost(\'' + row.inventoryNo + '\')"><i class="fa fa-edit"></i>遗失</a> ');
                        actions.push('<a class="btn btn-danger btn-xs " href="javascript:void(0)" onclick="scrap(\'' + row.inventoryNo + '\')"><i class="fa fa-edit"></i>报废</a> ');
                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);
    });
    var inventoryId = [[${inventoryId}]];
    var assetId = [[${assetId}]];
    function lost(inventoryNo) {
        layer.prompt({
            formType: 2,
            title: '遗失处理',
            // area: ['300px', '100px'],
            btnAlign: 'c',
            content: '<div><p>备注:</p><textarea name="txt_remark" id="remark" style="width:200px;height:100px;"></textarea></div>',
            yes: function(index, layero){
                // 获取文本框输入的值
                var value = $("#remark").val();
                $.modal.confirm("确定遗失处理？",function() {
                    $.operate.post(ctx + "inventory/scrap/lost",{inventoryNo:inventoryNo,assetId:assetId,remark:value,inventoryId:inventoryId},function () {
                        layer.close(index);
                    });
                });
            }
        });
    }
    function scrap(inventoryNo) {
        layer.prompt({
            formType: 2,
            title: '报废处理',
            // area: ['300px', '100px'],
            btnAlign: 'c',
            content: '<div><p>备注:</p><textarea name="txt_remark" id="remark" style="width:200px;height:100px;"></textarea></div>',
            yes: function (index, layero) {
                // 获取文本框输入的值
                var value = $("#remark").val();
                $.modal.confirm("确定报废处理？", function() {
                    $.operate.post(ctx + "inventory/scrap/scrap",{inventoryNo:inventoryNo,assetId:assetId,remark:value,inventoryId:inventoryId},function () {
                        layer.close(index);
                    });
                });
            }
        });
    }
    function lostAll() {
        var rows = $.table.selectFirstColumns();
        if (rows.length == 0) {
            $.modal.alertWarning("请至少选择一条记录");
            return;
        }
        $.modal.confirm("确认要遗失处理选中的" + rows.length + "条数据吗?", function() {
            var data = { "assetId": assetId, "inventoryNo": rows.join() };
            $.operate.submit(ctx + "inventory/scrap/lostAll", "post", "json", data);
        });
    }
    function scrapAll() {
        var rows = $.table.selectFirstColumns();
        if (rows.length == 0) {
            $.modal.alertWarning("请至少选择一条记录");
            return;
        }
        $.modal.confirm("确认要报废处理选中的" + rows.length + "条数据吗?", function() {
            var data = { "assetId": assetId, "inventoryNo": rows.join() };
            $.operate.submit(ctx + "inventory/scrap/scrapAll", "post", "json", data);
        });
    }

    function submitHandler() {
        $.modal.close(layer.index);
        parent.$.table.refresh();
    }
</script>
</body>
</html>